<?php
	class UnitsController extends BaseController{
		public function getSelect($shop_id){
			try{
					echo $json = json_encode(Units::Select($shop_id));
			}
			catch(Exception $e){
				return ErrorResponse::SendErrorMessage($e->getMessage());
			}
		}

		public function postInsert($shop_id){
	    	//checks the information input
		    if(Input::has('name'))
		        {
		            $name=Input::get('name');
		        }
	        else
		        {
		            return ErrorResponse::SendErrorMessage('User name invalid');
		        }
	        if(Input::has('comments'))
		        {
		            $comments=Input::get('comments');
		        }
	        else
		        {
		            $comments='';
		        }
		    try{
		    	
		    	if($shop_id = Units::Insert($name,$comments,$shop_id))
	        	{
                	return Response::json(array('status'=>'success','shop_id'=>$shop_id));
	        	}
	        }
	        catch(Exception $e)
	        {
	            return ErrorResponse::SendErrorMessage($e->getMessage());
	        } 
    	}
    	public function postEdit($units_id){
	    	//checks the information input
		    if(Input::has('name'))
		        {
		            $name=Input::get('name');
		        }
	        else
		        {
		            return ErrorResponse::SendErrorMessage('User name invalid');
		        }
		    if(Input::has('comments'))
		        {
		            $comments=Input::get('comments');
		        }
	        else
		        {
		            $comments='';
		        }
		    try{
			    if(Units::Edit($name,$comments,$units_id))
		        	{
		        	
	                	return Response::json(array('status'=>'success'));
	                }
		    }
	        catch(Exception $e)
	        {
	            return ErrorResponse::SendErrorMessage($e->getMessage());
	        }
        }
        public function postDel($units_id){
	        try{
	        	if(Units::Del($units_id))
	        	{
	        		return Response::json(array('status'=>'success'));
	        	}	             
	        }
	        catch(Exception $e)
	        {
	            return ErrorResponse::SendErrorMessage($e->getMessage());
	        }
		}
 }
?>